<?php
include ('shujuku.php');
session_start();
$huoqu="SELECT *FROM msg1 ORDER BY id DESC ";
$mysql_result=$mysql->query($huoqu);

//while (true){
//    $row=$mysql_result->fetch_array(MYSQLI_ASSOC);
//    if($row==false){
//        break;
//    }
//}
$rows=array(); //变成数组
while ($row=$mysql_result->fetch_array(MYSQLI_ASSOC)){
    $rows[]=$row;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="2.css">
</head>
<body>
<div class="add">
    <form action="http://127.0.0.1:8080/php/ziji/2/index.php" method="post">

        <textarea name="mazmun" class="area"></textarea>

        <input name="user" class="text" type="text" />

        <input class="btn" type="submit" value="发布" />
        <a style="float: right" href="login.php">登记</a>
    </form>
    <div class="msg">
        <?php
           foreach ($rows as $row) {
               $t=date('y年m月d日 H:s:i',$row['time']);
            ?>
                <div class="item">
                    <span class="about"><?php echo $row['username'] ?></span>
                    <span class="time">
                        <?php echo $t ?>
                        <?php
                        if(isset($_SESSION['user'])) {
                            ?>
                            <a onclick="return confirm('你确定删除吗?')" href="delete.php?id=<?php echo $row['id']?>">删除</a>
                            <?php
                        }
                        ?>
                  </span>
                    <p><?php echo $row['contact'] ?></p>
                </div>
         <?php
          }
        ?>
    </div>
</div>
</body>
</html>